{
  LX Command module

  Based on modo's SDK lxcommand.h which is:

  Copyright (c) 2008-2012 Luxology LLC

  Permission is hereby granted, free of charge, to any person obtaining a
  copy of this software and associated documentation files (the "Software"),
  to deal in the Software without restriction, including without limitation
  the rights to use, copy, modify, merge, publish, distribute, sublicense,
  and/or sell copies of the Software, and to permit persons to whom the
  Software is furnished to do so, subject to the following conditions:

  The above copyright notice and this permission notice shall be included in
  all copies or substantial portions of the Software.   Except as contained
  in this notice, the name(s) of the above copyright holders shall not be
  used in advertising or otherwise to promote the sale, use or other dealings
  in this Software without prior written authorization.

  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  DEALINGS IN THE SOFTWARE.
}

{
  Copyright (c) 2012 David Ballesteros and Jameel Halabi

  This unit is part of the BLAISEmodo wrapper,
  which is licensed under the BSD 2-Clause license (see licenses/license.txt).
}


unit Lx_Command;

{$mode objfpc}{$H+}

interface

uses
  Lx_Result;

type
  PLXtCommandTag = ^LXtCommandTag;
  LXtCommandTag  = Word          ;

const
  LXa_ATTRIBUTESUI                        = 'attributesui'      ;
  LXa_COMMAND                             = 'command'           ;
  LXa_COMMANDBLOCK                        = 'commandblock'      ;
  LXa_COMMANDEVENT                        = 'commandevent'      ;
  LXa_COMMANDPOSTEND                      = 'commandpostmodeend';
  LXa_COMMANDSERVICE                      = 'commandservice'    ;
  LXa_COMMANDDBHELP                       = 'commanddbhelp'     ;
  LXa_UIHINTS                             = 'uihints'           ;
  LXa_UIVALUEHINTS                        = 'uivaluehints'      ;

  LXfCMD_SELECT                           = $00000080;
  LXfCMD_QUIET                            = $00000400;
  LXfCMD_POSTCMD                          = $00000800;
  LXfCMD_MUSTSETARG                       = $00001000;
  LXfCMD_EXTRA1                           = $00002000;
  LXfCMD_EXTRA2                           = $00004000;
  LXfCMD_SELECTIONLESS                    = $00008000;
  LXfCMD_INTERNAL                         = $00020000;
  LXfCMD_MOUSEDOWNOK                      = $00080000;

  // Init only flags
  LXfCMD_INIT_ONLY                        = $000FFFF0;

  LXfCMD_REPEAT                           = $00100000;
  LXfCMD_DEFER_INTERACTIVITY              = $00200000;

  LXfCMD_UI                               = $01000000;
  LXfCMD_MODEL                            = $02000000;

  { Used for testing for undoable commands only;
    do NOT set command flags with this.
    Use LXfCMD_UNDO/LXfCMD_UNDO_UI to make an undoable command }
  LXfCMD_UNDO_INTERNAL                    = $04000000;

  LXfCMD_UNDO                             = LXfCMD_UNDO_INTERNAL or
                                            LXfCMD_MODEL           ;

  LXfCMD_UNDO_UI                          = LXfCMD_UNDO_INTERNAL or
                                            LXfCMD_UI              ;

  LXfCMD_UNDOSPECIAL                      = $08000000;
  LXfCMD_SANDBOXED                        = $10000000;

  // Type flags
  LXfCMD_TYPES                            = $FF000000;

  LXfCMDHINT_SUPPRESS_INFOS               = $00000001;
  LXfCMDHINT_SUPPRESS_WARNINGS            = $00000002;
  LXfCMDHINT_SUPPRESS_ERRORS              = $00000004;

  LXfCMD_ALERT_NONE                       = $0000;
  LXfCMD_ALERT_SHOWERR                    = $0001;
  LXfCMD_ALERT_SHOWERR_FORCESUB           = $0002;
  LXfCMD_ALERT_SHOWERR_FORCESUB_OFF       = $0004;
  LXfCMD_ALERT_SYNTAXERR                  = $0008;
  LXfCMD_ALERT_MASK                       = $00FF;

  LXfCMD_EXEC_NONE                        = $0000;
  LXfCMD_EXEC_GETARGS                     = $0100;
  LXfCMD_EXEC_GETARGS_FORCESUB            = $0200;
  LXfCMD_EXEC_GETARGS_FORCESUB_OFF        = $0400;
  LXfCMD_EXEC_ALWAYSGETARGS               = $0800;
  LXfCMD_EXEC_MASK                        = $FF00;
  LXfCMD_EXEC_PARENT_FLAGS_PASSED_MARKER  = $8000;

  LXfCMD_ALERT_DEFAULT                    = LXfCMD_ALERT_SHOWERR   or
                                            LXfCMD_ALERT_SYNTAXERR   ;

  LXfCMD_EXEC_DEFAULT                     = LXfCMD_ALERT_SHOWERR   or
                                            LXfCMD_ALERT_SYNTAXERR or
                                            LXfCMD_EXEC_GETARGS      ;

  LXfCMD_PARSED_FLAGS                     = $10000000;

  LXfCMDARG_INIT_ONLY                     = $0FFFF;
  LXfCMDARG_OPTIONAL                      = $00001;
  LXfCMDARG_QUERY                         = $00002;
  LXfCMDARG_READONLY                      = $00004;
  LXfCMDARG_VARIABLE                      = $00008;
  LXfCMDARG_DYNAMICHINTS                  = $00010;
  LXfCMDARG_REQFORVARIABLE                = $00020;
  LXfCMDARG_HIDDEN                        = $00040;
  LXfCMDARG_DYNAMIC_DEFAULTS              = $00080;
  LXfCMDARG_DIALOG_ALWAYS_SETS            = $00100;
  LXfCMDARG_CAN_QUERY_WHEN_DISABLED       = $00200;
  LXfCMDARG_DIALOG_DIVIDER_AFTER_ARG      = $00400;

  LXfCMDARG_STATE_ONLY                    = $F0000;
  LXfCMDARG_VALUE_SET                     = $10000;
  LXfCMDARG_CHANGED                       = $20000;
  LXfCMDARG_REQFORVAR_SET                 = $40000;

  LXfVALHINT_POPUPS                       = $001;
  LXfVALHINT_POPUP_DIRECT                 = $002;
  LXfVALHINT_POPUP_ALPHA_SORT             = $004;
  LXfVALHINT_ITEMS                        = $008;
  LXfVALHINT_ITEMS_NONE                   = $010;
  LXfVALHINT_FORM_COMMAND_LIST            = $020;

  LXfPOPFLAGS_SELECTED                    = $010;
  LXfPOPFLAGS_UNSELECTED                  = $020;
  LXfPOPFLAGS_MIXED                       = $030;
  LXfPOPFLAGS_DISABLED                    = $080;

  LXfCMDNOTIFY_VALUE                      = $01;
  LXfCMDNOTIFY_LABEL                      = $02;
  LXfCMDNOTIFY_DISABLE                    = $04;
  LXfCMDNOTIFY_DATATYPE                   = $08;
  LXfCMDNOTIFY_CHANGE_ALL                 = $0F;

  LXfCMDBLOCK_PRESERVE_SELECTION          = $000100;
  LXfCMDBLOCK_UI                          = $010000;
  LXfCMDBLOCK_UNDO_UI                     = $020000;
  LXfCMDBLOCK_SANDBOXED                   = $040000;
  LXfCMDBLOCK_POSTMODE                    = $100000;
  LXfCMDBLOCK_STEPUNDO                    = $200000;

  LXfCMDSANDBOX_ALLOW_UI                  = 1;

  LXiCTAG_NULL                            = LXtCommandTag(0);

  LXiCMD_EXEC_WITH_PARENTS_FLAGS          = -1;

  LXiBOOLEANSTYLE_DEFAULT                 = 0;
  LXiBOOLEANSTYLE_CHECKMARK               = 1;
  LXiBOOLEANSTYLE_BUTTON                  = 2;

  LXiCMDENTRYTYPE_INVALID                 = 0;
  LXiCMDENTRYTYPE_COMMAND                 = 1;
  LXiCMDENTRYTYPE_BLOCK                   = 2;

  LXiCMDSTATUS_INITIALIZING               = 0;
  LXiCMDSTATUS_NORMAL                     = 1;
  LXiCMDSTATUS_EXECUTING_STARTUP_COMMANDS = 2;

  LXiCMD_SEP_DOT                          = 0;
  LXiCMD_SEP_BACKSLASH                    = 1;
  LXiCMD_SEP_SLASH                        = 2;
  LXiCMD_SEP_COLON                        = 3;

  LXiCMDREFIRE_NONE                       = 0;
  LXiCMDREFIRE_PENDING                    = 1;
  LXiCMDREFIRE_COMMAND                    = 2;
  LXiCMDREFIRE_BLOCK                      = 3;

  LXmCMDHINT_SUPPRESS_DIALOGS             = LXfCMDHINT_SUPPRESS_INFOS    or
                                            LXfCMDHINT_SUPPRESS_WARNINGS or
                                            LXfCMDHINT_SUPPRESS_ERRORS     ;

  LXmPOPFLAGS_GROUP_MASK                  = $00F;

  LXsCMD_CONTAINER_NAME                   = 'command.container.name' ;
  LXsCMD_CONTAINER_ARGS                   = 'command.container.args' ;
  LXsCMD_CONTAINER_TYPES                  = 'command.container.types';

  LXu_ATTRIBUTESUI   = '{44D9C65E-AE2E-4012-AB57-E2839734F7FF}';
  LXu_COMMAND        = '{4F540BF1-F97E-4D46-8A5F-6B2750A6CEB9}';
  LXu_COMMANDBLOCK   = '{65AEBD9F-D518-47b2-8CC6-E453F8C43CB6}';
  LXu_COMMANDDBHELP  = '{7c8a58e0-0052-4d8e-addb-7387fba9d5bf}';
  LXu_COMMANDEVENT   = '{F7CD29B5-6858-445b-BE6D-8347603B47E9}';
  LXu_COMMANDPOSTEND = '{AEB6B7BF-34B9-4991-904C-298B8DB1AE12}';
  LXu_COMMANDSERVICE = '{9DB8BA65-8C36-45A7-B403-DF7BA59BA6C2}';
  LXu_UIHINTS        = '{944D9CFD-DB04-4bba-B8B1-ADE424695EDC}';
  LXu_UIVALUEHINTS   = '{f37bb385-7214-42d5-9bed-552ff4738908}';
  LXu_UIVALUEHINTS1  = '{7BB10C3F-1FFB-4104-8FBE-CB1C334EE3C1}';

type
  ILxCommand = interface
  [LXu_COMMAND]
    function  Tag
              (      Tag           : PLXtCommandTag) : LxResult;

    function  Name
              (      Name          : PPChar        ) : LxResult;

    function  UserName
              (      UserName      : PPChar        ) : LxResult;

    function  ButtonName
              (      ButtonName    : PPChar        ) : LxResult;

    function  Desc
              (      Desc          : PPChar        ) : LxResult;

    function  Tooltip
              (      Tooltip       : PPChar        ) : LxResult;

    function  Help
              (      Help          : PPChar        ) : LxResult;

    function  Example
              (      Example       : PPChar        ) : LxResult;

    function  Icon
              (      IconNames     : PPChar        ) : LxResult;

    function  Flags
              (      Flags_        : PUInt32       ) : LxResult;

    function  PostExecFlags
              (      Flags_        : PUInt32       ) : LxResult;

    function  PostExecBehaviorFlags
              (      Flags_        : PUInt32       ) : LxResult;

    function  PostExecHints
              (      Hints         : PUInt32       ) : LxResult;

    function  SandboxGUID
              (      GUID          : PPGuid        ) : LxResult;

    function  Message
              (  out VObj                          ) : LxResult;

    function  Enable
              (      Msg           : IUnknown      ) : LxResult;

    function  ContainedEnable
              (      Types         : PLXtID4       ) : LxResult;

    procedure Interact                               ;

    procedure PreExecute                             ;

    procedure Execute
              (      Flags_        : PUInt32       ) ;

    function  ToggleArg
              (      Index         : PUInt32       ;
                     Value         : PPointer      ;
                     TypeID        : PUInt32       ;
                     TypeName      : PPChar        ) : LxResult;

    function  ArgFlags
              (      Index         : UInt32        ;
                     Flags_        : PUInt32       ) : LxResult;

    function  ArgClear
              (      Index         : UInt32        ) : LxResult;

    function  ArgResetAll                            : LxResult;

    function  ArgSetDatatypes                        : LxResult;

    function  ArgUserName
              (      Index         : UInt32        ;
                     UserName_     : PPChar        ) : LxResult;

    function  ArgDesc
              (      Index         : PUInt32       ;
                     Desc_         : PPChar        ) : LxResult;

    function  ArgExample
              (      Index         : UInt32        ;
                     Example_      : PUInt32       ) : LxResult;

    function  ArgType
              (      Index         : UInt32        ;
                     &Type         : PPChar        ) : LxResult;

    function  ArgTypeUserName
              (      Index         : UInt32        ;
                     UserName_     : PUInt32       ) : LxResult;

    function  ArgTypeDesc
              (      Index         : PUInt32       ;
                     Desc_         : PPChar        ) : LxResult;

    function  ArgOptionUserName
              (      Index         ,
                     OptIndex      : UInt32        ;
                     UserName_     : PPChar        ) : LxResult;

    function  ArgOptionDesc
              (      Index         ,
                     OptIndex      : UInt32        ;
                     Desc_         : PPChar        ) : LxResult;

    function  DialogInit                             : LxResult;

    function  DialogArgChange
              (      Arg           : UInt32        ) : LxResult;

    function  ArgEnable
              (      Arg           : UInt32        ) : LxResult;

    function  ArgParseString
              (      ArgIndex      : UInt32        ;
               const ArgString     : PPChar        ) : LxResult;

    function  Copy
              (      SourceCommand : IUnknown      ) : LxResult;

    function  Query
              (      Index         : UInt32        ;
                     VaQuery       : IUnknown      ) : LxResult;

    function  NotifyAddClient
              (      Argument      : Integer       ;
                     &Object       : IUnknown      ) : LxResult;

    function  NotifyRemoveClient
              (      &Object       : IUnknown      ) : LxResult;
  end;

  ILxCommandDBHelp  = interface
  [LXu_COMMANDDBHELP]
    function DBHelp(const DBHelp : PPChar) : LxResult;
  end;

  ILxUIHints  = interface
  [LXu_UIHINTS]
    function &Class            (const C       : PChar  ) : LxResult;
    function &Label            (const CLabel  : PChar  ) : LxResult;
    function MinInt            (      Min     : Integer) : LxResult;
    function MaxInt            (      Max     : Integer) : LxResult;
    function MinFloat          (      Min     : Double ) : LxResult;
    function MaxFloat          (      Max     : Double ) : LxResult;
    function StepInt           (      Step    : Integer) : LxResult;
    function StepFloat         (      Step    : Double ) : LxResult;
    function Track             (      State   : UInt32 ) : LxResult;
    function StringList        (      Strings : PPChar ) : LxResult;
    function TextLines         (      Lines   : UInt32 ) : LxResult;
    function TextFixedWidthFont(      State   : UInt32 ) : LxResult;
    function TextPasswordMode  (      State   : UInt32 ) : LxResult;
    function ValuePresetCookie (const Cookie  : PChar  ) : LxResult;
    function ForceUpdate                                 : LxResult;
    function BooleanStyle      (      Style   : UInt32 ) : LxResult;
  end;

  ILxUIValueHints  = interface
  [LXu_UIVALUEHINTS]
    function Flags                                                 : UInt32  ;
    function PopCount                                              : UInt32  ;
    function PopUserName           (      Index        : UInt32  ) : PChar   ;
    function PopInternalName       (      Index        : UInt32  ) : PChar   ;
    function PopIconSize           (      W            ,
                                          H            : Integer ) : UInt32  ;
    function PopIconImage          (      Index        : UInt32  ;
                                      out VObj                   ) : LxResult;
    function PopIconResource       (      Index        : UInt32  ;
                                    const IconResource : PPChar  ) : LxResult;
    function PopFlags              (      Index        : UInt32  ;
                                          Flags_       : PUInt32 ) : PChar   ;
    function PopCategory           (const Category     : PPChar  ) : LxResult;
    function ItemTest              (      Item         : IUnknown) : LxResult;
    function ColorPickerCommands   (      RGB          ,
                                          Alpha        ,
                                          RGBAlt       ,
                                          AlphaAlt     ,
                                          UseAlt       : PChar   ;
                                          BufLens      : UInt32  ) : LxResult;
    function NotifierCount         (      Count        : UInt32  ) : LxResult;
    function NotifierByIndex       (      Index        : Integer ;
                                    const Name         : PChar   ;
                                    const Args         : PChar   ) : LxResult;
    function FormCommandListCount  (      Count        : PUInt32 ) : LxResult;
    function FormCommandListByIndex(      Index        : Integer ;
                                    const Command      : PChar   ) : LxResult;
  end;

  ILxUIValueHints1  = interface
  [LXu_UIVALUEHINTS1]
    function Flags                                             : UInt32  ;
    function PopCount                                          : UInt32  ;
    function PopUserName           (      Index    : UInt32  ) : PChar   ;
    function PopInternalName       (      Index    : UInt32  ) : PChar   ;
    function PopFlags              (      Index    : UInt32  ;
                                          Flags_   : PUInt32 ) : PChar   ;
    function PopCategory           (const Category : PPChar  ) : LxResult;
    function ItemTest              (      Item     : IUnknown) : LxResult;
    function ColorPickerCommands   (      RGB      : PChar   ;
                                          Alpha    : PChar   ;
                                          RGBAlt   : PChar   ;
                                          AlphaAlt : PChar   ;
                                          UseAlt   : PChar   ;
                                          BufLens  : UInt32  ) : LxResult;
    function NotifierCount         (      Count    : UInt32  ) : LxResult;
    function NotifierByIndex       (      Index    : Integer ;
                                    const Name     : PChar   ;
                                    const Args     : PChar   ) : LxResult;
    function FormCommandListCount  (      Count    : PUInt32 ) : LxResult;
    function FormCommandListByIndex(      Index    : Integer ;
                                    const Command  : PChar   ) : LxResult;
  end;

  ILxAttributesUI  = interface
  [LXu_ATTRIBUTESUI]
    function UIHints     (    Index : UInt32  ;
                              Hints : IUnknown) : LxResult;
    function UIValueHints(    Index : UInt32  ;
                          out VObj            ) : LxResult;
    function DisableMsg  (    Index : UInt32  ;
                              Msg   : IUnknown) : LxResult;
  end;

  ILxCommandEvent  = interface
  [LXu_COMMANDEVENT]
    function Event(Flags : UInt32) : LxResult;
  end;

  ILxCommandBlock  = interface
  [LXu_COMMANDBLOCK]
    function Name         (const Name   : PPChar ) : LxResult;
    function Flags        (      Flags  : PUInt32) : LxResult;
    function SubExecs     (      Execs  : PUInt32) : LxResult;
    function PostExecFlags(      Flags_ : PUInt32) : LxResult;
  end;

  ILxCommandService  = interface
  [LXu_COMMANDSERVICE]
    function ScriptQuery
             (  out VObj                           ) : LxResult;

    function MasterStatus
             (      Status          : PUInt32      ) : LxResult;

    function GetNameSep
             (      Sep             : PUInt32      ) : LxResult;

    function SetNameSep
             (      Sep             : PUInt32      ) : LxResult;

    function Proto
             (const Name            : PChar        ;
                out VObj                           ) : LxResult;

    function ProtoFromCommand
             (      Cmd             : IUnknown     ;
                out VObj                           ) : LxResult;

    function Lookup
             (const Name            : PChar        ;
                out VObj                           ) : LxResult;

    function Spawn
             (      Tag             : LXtCommandTag;
              const Name            : PChar        ;
                out Cmd                            ) : LxResult;

    function SpawnFromCommand
             (      Cmd             : IUnknown     ;
                out Spawn_                         ) : LxResult;

    function SpawnFromString
             (const Args            : Char         ;
                    ExecFlags       : UInt32       ;
                    QueryArgIndex   : Integer      ;
               out  Spawn_                         ) : LxResult;

    function ExecuteArgString
             (      ExecFlags       : UInt32       ;
                    Tag             : LXtCommandTag;
              const Args            : PChar        ) : LxResult;

    function ExecuteToggleArgString
             (      ExecFlags       : UInt32       ;
                    Tag             : LXtCommandTag;
              const Args            : PChar        ;
                    NewState        : Integer      ) : LxResult;

    function IsToggleArgString
             (const &String         : PChar        ) : LxResult;

    function IsBooleanArgString
             (const &String         : PChar        ) : LxResult;

    function ExecuteBooleanArgString
             (      ExecFlags       : UInt32       ;
                    Tag             : LXtCommandTag;
              const Args            : PChar        ) : LxResult;

    function ExecuteSpecial
             (      ExecFlags       : UInt32       ;
                    Cmd             : IUnknown     ;
                    SpecialArgIndex : Integer      ) : LxResult;

    function ExecuteAttribObject
             (      ExecFlags       : UInt32       ;
                    Tag             : LXtCommandTag;
              const CmdName         : PChar        ;
                    AttribArgs      : IUnknown     ) : LxResult;

    function ProcessStringFlags
             (      Flags           : UInt32       ;
              const &String         : PChar        ;
                    NewFlags        : UInt32       ;
                    AfterFlags      : PPChar       ) : LxResult;

    function ExecFlagsAsPrefixString
             (      Flags           : UInt32       ;
                    Buffer          : PChar        ;
                    Len             : UInt32       ) : LxResult;

    function SetToggleArgState
             (      Cmd             : IUnknown     ;
                    State           : Integer      ) : LxResult;

    function GetToggleArgState
             (      Cmd             : IUnknown     ;
                    State           : PInteger     ;
                out VObj                           ) : LxResult;

    function IsImplicitScript
             (const Def             : PChar        ) : LxResult;

    function SpawnImplicitScript
             (const Def             : PChar        ;
                out VObj                           ) : LxResult;

    function ExecuteImplicitScript
             (const Def             : PChar        ;
                    ExecFlags       : UInt32       ) : LxResult;

    function RefireBegin                             : LxResult;

    function RefireEnd                               : LxResult;

    function RefireState
             (      State           : UInt32       ) : LxResult;

    function RefireCmd
             (  out Cmd                            ) : LxResult;

    function RefireBlock
             (const Name            : PChar        ) : LxResult;

    function PostModeBegin
             (      Cmd             : IUnknown     ;
                    Tag             : LXtCommandTag;
              const Name            : PChar        ;
              const Args            : PChar        ;
                    PostEndObj      : IUnknown     ) : LxResult;

    function PostModeEnd                             : LxResult;

    function PostModeState                           : LxResult;

    function PostModeRestart                         : LxResult;

    function CurrentExecDepth
             (      Depth           : Integer      ) : LxResult;

    function BlockBegin
             (const Name            : PChar        ;
                    Flags           : UInt32       ) : LxResult;

    function BlockEnd                                : LxResult;

    function BlockCurrent
             (  out Block                          ) : LxResult;

    function SandboxFlags
             (      Flags           : PUInt32      ) : LxResult;

    function SandboxAddObject
             (      &Object         : IUnknown     ) : LxResult;

    function SandboxObjectCount
             (      Count           : PUInt32      ) : LxResult;

    function SandboxObjectByIndex
             (      Index           : UInt32       ;
                out VObj                           ) : LxResult;

    function SandboxObjectLookup
             (      GUID            : TGuid        ;
                out VObj                           ) : LxResult;

    function SandboxObjectByCommand
             (      Cmd             : IUnknown     ;
                out VObj                           ) : LxResult;

    function SandboxBegin
             (      Flags           : UInt32       ) : LxResult;

    function SandboxState                            : LxResult;

    function SandboxEnd                              : LxResult;

    function ParseArgString
             (      Cmd             : IUnknown     ;
                    AlertFlags      : Integer      ;
                    Args            : PChar        ) : LxResult;

    function ParseAttribObject
             (      Cmd             : IUnknown     ;
                    AlertFlags      : UInt32       ;
                    AttribArgs      : IUnknown     ) : LxResult;

    function Usage
             (      Cmd             : IUnknown     ;
                    Buffer          : PPChar       ) : LxResult;

    function ArgsAsString
             (      Cmd             : IUnknown     ;
                    Buffer          : PChar        ;
                    BufLen          : UInt32       ;
                    IncludeCmd      : UInt32       ) : LxResult;

    function Query
             (      Cmd             : IUnknown     ;
                    Index           : UInt32       ;
                out VObj                           ) : LxResult;

    function QueryArgString
             (      Cmd             : IUnknown     ;
                    AlertFlags      : UInt32       ;
              const Args            : PChar        ;
                out VaQuery                        ;
                    Queryindex      : UInt32       ;
                    IncludesCmdName : UInt32       ) : LxResult;

    function CreateQueryObject
             (const TypeName        : PChar        ;
                out VaQuery                        ) : LxResult;

    function AliasCreate
             (const AliasName       : PChar        ;
                    TargetCmd       : IUnknown     ;
                    TargetTag       : LXtCommandTag;
              const TargetName      : PChar        ;
              const Args            : PChar        ) : LxResult;

    function AliasDelete
             (      Alias           : IUnknown     ;
                    Tag             : LXtCommandTag;
              const Name            : PChar        ) : LxResult;

    function IsContainer
             (      Cmd             : IUnknown     ) : LxResult;

    function IsAliased
             (      Cmd             : IUnknown     ) : LxResult;

    function CommandCount
             (      Count           : PUInt32      ) : LxResult;

    function CommandByIndex
             (      Index           : UInt32       ;
                out Cmd                            ) : LxResult;

    function ExecEntryType
             (      Index           : Integer      ;
                    &Type           : PInteger     ) : LxResult;

    function ExecEntryUserName
             (      Index           : Integer      ;
              const UserName        : PPChar       ) : LxResult;

    function ExecEntryName
             (      Index           : Integer      ;
              const Name            : PPChar       ) : LxResult;

    function ExecEntryAsArgString
             (      Index           : Integer      ;
                    Buffer          : PChar        ;
                    Len             : Integer      ) : LxResult;

    function IsGlobalInteractionOK                   : LxResult;


    function ArgsAsStringLen
             (      Cmd             : IUnknown     ;
                    Buffer          : PChar        ;
                    BufLen          : UInt32       ;
                    IncludeCmd      : UInt32       ) : LxResult;
  end;

  ILxCommandPostEnd  = interface
  [LXu_COMMANDPOSTEND]
    function &End : LxResult;
  end;

function LXe_CMD_ALREADY_EXISTS                                      : LxResult;
function LXe_CMD_MISSING_ARGS                                        : LxResult;
function LXe_CMD_NOT_AVAILABLE                                       : LxResult;
function LXe_CMD_DISABLED                                            : LxResult;
function LXe_CMD_UNKNOWN_COMMAND                                     : LxResult;
function LXe_CMD_INVALID_ON_PROTO                                    : LxResult;
function LXe_CMD_DIFFERENT_TYPES                                     : LxResult;
function LXe_CMD_UNBALANCED_BRACES                                   : LxResult;
function LXe_CMD_BAD_DEFINITION                                      : LxResult;
function LXe_CMD_UNKNOWN_ARGUMENT                                    : LxResult;
function LXe_CMD_TOO_MANY_ARGUMENTS                                  : LxResult;
function LXe_CMD_ARGUMENT_ALREADY_SET                                : LxResult;
function LXe_CMD_ARGUMENT_NOT_QUERYABLE                              : LxResult;
function LXe_CMD_NO_QUERY_MARKED                                     : LxResult;
function LXe_CMD_TOO_MANY_QUERIES_MARKED                             : LxResult;
function LXe_CMD_ILLEGAL_REFIRE_BEGIN                                : LxResult;
function LXe_CMD_ILLEGAL_REFIRE_END                                  : LxResult;
function LXe_CMD_ALREADY_REFIRING                                    : LxResult;
function LXe_CMD_NOT_ALIASED                                         : LxResult;
function LXe_CMD_ERROR_SETTING_DATATYPE                              : LxResult;
function LXe_CMD_ERROR_ARG_MISSING_VALUE                             : LxResult;
function LXe_CMD_SANDBOX_NOT_COMPATIBLE                              : LxResult;
function LXe_CMD_SANDBOX_ONLY                                        : LxResult;
function LXe_CMD_EXPECTED_OPENING_BRACE                              : LxResult;
function LXe_CMD_VARIABLE_DATATYPES_SET                              : LxResult;
function LXe_CMD_VARIABLE_DATATYPES_PENDING                          : LxResult;
function LXe_CMD_REQUIRES_USER_INTERACTION                           : LxResult;
function LXe_CMD_HAS_NO_ARGUMENTS                                    : LxResult;
function LXe_CMD_QUERY_MISMATCHED_DATATYPES                          : LxResult;
function LXe_CMD_SANDBOX_GLOBAL                                      : LxResult;
function LXe_CMD_SANDBOXED                                           : LxResult;

function LXxCMD_IS_SIDEEFFECT                (      Flags : Integer) : Boolean ;
function LXxCMD_EXEC_WITH_PARENTS_FLAGS      (const Flags : Integer) : Boolean ;
function LXxCMD_EXEC_MASK                    (const Flags : Integer) : Integer ;
function LXxCMD_IS_USER_INTERACTION_OK       (const Flags : Integer) : Boolean ;
function LXxCMD_EXEC_WERE_PARENT_FLAGS_PASSED(const Flags : Integer) : Integer ;

function LXxCMDARG_ISREQFORVARIABLE          (const F     : Integer) : Integer ;
function LXxCMDARG_ISVARIABLE                (const F     : Integer) : Integer ;
function LXxCMDARG_ISREQUIRED                (const F     : Integer) : Boolean ;
function LXxCMDARG_ISNEEDED                  (const F     : Integer) : Boolean ;
function LXxCMDARG_ISQUERY                   (const F     : Integer) : Boolean ;
function LXxCMDARG_ISSET                     (const F     : Integer) : Boolean ;

implementation

function LXe_CMD_ALREADY_EXISTS                                      : LxResult; inline;
begin
  Result := LXxFAILCODE(LXeSYS_CMDS,  1);
end;
function LXe_CMD_MISSING_ARGS                                        : LxResult; inline;
begin
  Result := LXxFAILCODE(LXeSYS_CMDS,  2);
end;
function LXe_CMD_NOT_AVAILABLE                                       : LxResult; inline;
begin
  Result := LXxFAILCODE(LXeSYS_CMDS,  3);
end;
function LXe_CMD_DISABLED                                            : LxResult; inline;
begin
  Result := LXxFAILCODE(LXeSYS_CMDS,  4);
end;
function LXe_CMD_UNKNOWN_COMMAND                                     : LxResult; inline;
begin
  Result := LXxFAILCODE(LXeSYS_CMDS,  5);
end;
function LXe_CMD_INVALID_ON_PROTO                                    : LxResult; inline;
begin
  Result := LXxFAILCODE(LXeSYS_CMDS,  6);
end;
function LXe_CMD_DIFFERENT_TYPES                                     : LxResult; inline;
begin
  Result := LXxFAILCODE(LXeSYS_CMDS,  7);
end;
function LXe_CMD_UNBALANCED_BRACES                                   : LxResult; inline;
begin
  Result := LXxFAILCODE(LXeSYS_CMDS,  8);
end;
function LXe_CMD_BAD_DEFINITION                                      : LxResult; inline;
begin
  Result := LXxFAILCODE(LXeSYS_CMDS,  9);
end;
function LXe_CMD_UNKNOWN_ARGUMENT                                    : LxResult; inline;
begin
  Result := LXxFAILCODE(LXeSYS_CMDS, 10);
end;
function LXe_CMD_TOO_MANY_ARGUMENTS                                  : LxResult; inline;
begin
  Result := LXxFAILCODE(LXeSYS_CMDS, 11);
end;
function LXe_CMD_ARGUMENT_ALREADY_SET                                : LxResult; inline;
begin
  Result := LXxFAILCODE(LXeSYS_CMDS, 12);
end;
function LXe_CMD_ARGUMENT_NOT_QUERYABLE                              : LxResult; inline;
begin
  Result := LXxFAILCODE(LXeSYS_CMDS, 13);
end;
function LXe_CMD_NO_QUERY_MARKED                                     : LxResult; inline;
begin
  Result := LXxFAILCODE(LXeSYS_CMDS, 14);
end;
function LXe_CMD_TOO_MANY_QUERIES_MARKED                             : LxResult; inline;
begin
  Result := LXxFAILCODE(LXeSYS_CMDS, 15);
end;
function LXe_CMD_ILLEGAL_REFIRE_BEGIN                                : LxResult; inline;
begin
  Result := LXxFAILCODE(LXeSYS_CMDS, 16);
end;
function LXe_CMD_ILLEGAL_REFIRE_END                                  : LxResult; inline;
begin
  Result := LXxFAILCODE(LXeSYS_CMDS, 17);
end;
function LXe_CMD_ALREADY_REFIRING                                    : LxResult; inline;
begin
  Result := LXxFAILCODE(LXeSYS_CMDS, 18);
end;
function LXe_CMD_NOT_ALIASED                                         : LxResult; inline;
begin
  Result := LXxFAILCODE(LXeSYS_CMDS, 19);
end;
function LXe_CMD_ERROR_SETTING_DATATYPE                              : LxResult; inline;
begin
  Result := LXxFAILCODE(LXeSYS_CMDS, 20);
end;
function LXe_CMD_ERROR_ARG_MISSING_VALUE                             : LxResult; inline;
begin
  Result := LXxFAILCODE(LXeSYS_CMDS, 21);
end;
function LXe_CMD_SANDBOX_NOT_COMPATIBLE                              : LxResult; inline;
begin
  Result := LXxFAILCODE(LXeSYS_CMDS, 22);
end;
function LXe_CMD_SANDBOX_ONLY                                        : LxResult; inline;
begin
  Result := LXxFAILCODE(LXeSYS_CMDS, 23);
end;
function LXe_CMD_EXPECTED_OPENING_BRACE                              : LxResult; inline;
begin
  Result := LXxFAILCODE(LXeSYS_CMDS, 24);
end;
function LXe_CMD_VARIABLE_DATATYPES_SET                              : LxResult; inline;
begin
  Result := LXxFAILCODE(LXeSYS_CMDS, 25);
end;
function LXe_CMD_VARIABLE_DATATYPES_PENDING                          : LxResult; inline;
begin
  Result := LXxFAILCODE(LXeSYS_CMDS, 26);
end;
function LXe_CMD_REQUIRES_USER_INTERACTION                           : LxResult; inline;
begin
  Result := LXxFAILCODE(LXeSYS_CMDS, 27);
end;
function LXe_CMD_HAS_NO_ARGUMENTS                                    : LxResult; inline;
begin
  Result := LXxFAILCODE(LXeSYS_CMDS, 28);
end;
function LXe_CMD_QUERY_MISMATCHED_DATATYPES                          : LxResult; inline;
begin
  Result := LXxFAILCODE(LXeSYS_CMDS, 29);
end;
function LXe_CMD_SANDBOX_GLOBAL                                      : LxResult; inline;
begin
  Result := LXxGOODCODE(LXeSYS_CMDS,  1);  // Good, not Fail
end;
function LXe_CMD_SANDBOXED                                           : LxResult; inline;
begin
  Result := LXxGOODCODE(LXeSYS_CMDS,  2);  // Good, not Fail
end;

function LXxCMD_IS_SIDEEFFECT                (      Flags : Integer) : Boolean ; inline;
begin
  Result :=  ((Flags and LXfCMD_TYPES) = 0);
end;
function LXxCMD_EXEC_WITH_PARENTS_FLAGS      (const Flags : Integer) : Boolean ; inline;
begin
  Result := Flags = LXiCMD_EXEC_WITH_PARENTS_FLAGS;
end;
function LXxCMD_EXEC_MASK                    (const Flags : Integer) : Integer ; inline;
begin
  Result := Flags and LXfCMD_EXEC_MASK;
end;
function LXxCMD_IS_USER_INTERACTION_OK       (const Flags : Integer) : Boolean ; inline;
begin
  Result := Boolean(Flags and LXfCMD_EXEC_GETARGS      ) or
            Boolean(Flags and LXfCMD_EXEC_ALWAYSGETARGS)   ;
end;
function LXxCMD_EXEC_WERE_PARENT_FLAGS_PASSED(const Flags : Integer) : Integer ; inline;
begin
  Result := Flags and LXfCMD_EXEC_PARENT_FLAGS_PASSED_MARKER;
end;

function LXxCMDARG_ISREQFORVARIABLE          (const F     : Integer) : Integer ; inline;
begin
  Result := F and LXfCMDARG_REQFORVARIABLE;
end;
function LXxCMDARG_ISVARIABLE                (const F     : Integer) : Integer ; inline;
begin
  Result := F and LXfCMDARG_VARIABLE;
end;
function LXxCMDARG_ISREQUIRED                (const F     : Integer) : Boolean ; inline;
begin
  Result := ((F and LXfCMDARG_INIT_ONLY) = 0                       ) or
            ((F and LXfCMDARG_INIT_ONLY) = LXfCMDARG_REQFORVARIABLE)   ;
end;
function LXxCMDARG_ISNEEDED                  (const F     : Integer) : Boolean ; inline;
begin
  Result := Boolean(not (F and LXfCMDARG_OPTIONAL)) and
            Boolean(not (F and LXfCMDARG_READONLY))    ;
end;
function LXxCMDARG_ISQUERY                   (const F     : Integer) : Boolean ; inline;
begin
  Result := Boolean(F and LXfCMDARG_QUERY   ) or
            Boolean(F and LXfCMDARG_READONLY);
end;
function LXxCMDARG_ISSET                     (const F     : Integer) : Boolean ; inline;
begin
  Result := Boolean(F and LXfCMDARG_VALUE_SET);
end;

end.

